package com.xiangwei.service.impl;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;

import com.xiangwei.dao.TemplateMapper;
import com.xiangwei.entity.Template;
import com.xiangwei.service.ITemplateService;
import com.xiangwei.util.Common;
import com.xiangwei.util.StringUtils;

/**
 * @date 2015-7-21
 * @author tangshashan
 * @version V0.1
 * @brief 模版表Service处理类
 */
@Service
public class TemplateServiceImpl implements ITemplateService {
    @Resource
    private TemplateMapper templateMapper;

	@Override
	public void insertTemplate(Template template) {
		templateMapper.insertSelective(template);
	}

	@Override
	public List<Template> selectTemplateList() {
		return templateMapper.selectTemplateList();
	}

	@Override
	public int updateByPrimaryKeySelective(Template template) {
		return templateMapper.updateByPrimaryKeySelective(template);
	}

	@Override
	public int checkTemplateCode(Map<String, Object> map) {
		return templateMapper.checkTemplateCode(map);
	}

	@Override
	public int saveTemplate(Template template) {
		if(StringUtils.isEqual("", template.getId())){
			template.setId(Common.getUUID());
			return templateMapper.insertSelective(template);
		}else{
			return templateMapper.updateByPrimaryKeySelective(template);
		}
		
	}

	@Override
	public Template selectTemplateInfo(String id) {
		return templateMapper.selectByPrimaryKey(id);
	}

	@Override
	public int deleteTemplateById(String id) {
		if(!Common.isEmptyString(id)){
			return 0;
		}
		return templateMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Integer getHtml(String id) {
		if(!Common.isEmptyString(id)){
			return null;
		}
		Template template = templateMapper.selectByPrimaryKey(id);
		if(Common.isNullOrEmpty(template)){
			return null;
		}
		return template.getTemplateCode();
	}

}
